package com.itheima.springbootautoconfigureredis.config;

import com.itheima.springbootautoconfigureredis.pojo.MyRedisProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

@Configuration
@EnableConfigurationProperties(MyRedisProperties.class)
@ConditionalOnClass(Jedis.class)
public class RedisAutoConfiguration {
    /**
     * 提供Jedis的bean
     */
    @Bean
    @ConditionalOnMissingBean(name = "jedis")
    public Jedis jedis(MyRedisProperties myRedisProperties) {
        System.out.println("RedisAutoConfiguration....");
        return new Jedis(myRedisProperties.getHost(), myRedisProperties.getPort());
    }
}
